import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"
import { ConfigEnum } from "/@/enums/httpEnum"

export const pageStore = (params) => defHttp.get({ url: "/misc-service/store/pageStore", params })
export const listStore = (params) => defHttp.get({ url: "/misc-service/store/listStore", params })
export const getStore = (params) => defHttp.get({ url: "/misc-service/store/getStore", params })
export const deleteStore = (params, handleSuccess) => {
  return defHttp.delete({ url: "/misc-service/store/deleteStore", params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteStore = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/misc-service/store/batchDeleteStore", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

export const saveOrUpdateStore = (params, isUpdate) => {
  return defHttp.post({ url: isUpdate ? "/misc-service/store/updateStore" : "/misc-service/store/saveStore", params })
}

export const settingStore = (params) => defHttp.post({ url: "/misc-service/store/setting", params })

export const listStoreTag = (params) => defHttp.get({ url: "/misc-service/storeTag/listStoreTag", params })
export const saveOrUpdateStoreTag = (params, isUpdate) => {
  const url = isUpdate ? "/misc-service/storeTag/updateStoreTag" : "/misc-service/storeTag/saveStoreTag"
  return defHttp.post({ url: url, params })
}

export const deleteStoreTag = (params, handleSuccess) => {
  const headers = {}
  headers[RequestHeaderEnum.TENANT_ID] = params.tenantId
  return defHttp.delete({ url: "/misc-service/storeTag/deleteStoreTag", data: params, headers }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteStoreTag = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/misc-service/storeTag/batchDeleteStoreTag", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
